<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Load XML from a string</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domdocument.loadhtmlfile.html">DOMDocument::loadHTMLFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domdocument.normalizedocument.html">DOMDocument::normalizeDocument</a></div>
 <div class="up"><a href="class.domdocument.html">DOMDocument</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="domdocument.loadxml" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">DOMDocument::loadXML</h1>
  <p class="verinfo">(PHP 5)</p><p class="refpurpose"><span class="refname">DOMDocument::loadXML</span> &mdash; <span class="dc-title">
   Load XML from a string
  </span></p>

 </div>
 <div class="refsect1 description" id="refsect1-domdocument.loadxml-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <span class="methodname"><strong>DOMDocument::loadXML</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$source</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$options</code><span class="initializer"> = 0</span></span>
  ] )</div>

  <p class="para rdfs-comment">
   Loads an XML document from a string. 
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-domdocument.loadxml-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">source</code></em></dt>

     <dd>

      <p class="para">
       The string containing the XML.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">options</code></em></dt>

     <dd>

      <p class="para">
       <a href="language.operators.bitwise.html" class="link">Bitwise <em>OR</em></a>
       of the <a href="libxml.constants.html" class="link">libxml option constants</a>.
      </p>
     </dd>

    

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-domdocument.loadxml-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>TRUE</code></strong>， 或者在失败时返回 <strong><code>FALSE</code></strong>。 If called statically, returns a
   <a href="class.domdocument.html" class="classname">DOMDocument</a> 或者在失败时返回 <strong><code>FALSE</code></strong>.
  </p>
 </div>

 <div class="refsect1 errors" id="refsect1-domdocument.loadxml-errors">
  <h3 class="title">错误／异常</h3>
  <p class="para">
   If an empty string is passed as the <em><code class="parameter">source</code></em>,
   a warning will be generated. This warning is not generated by libxml
   and cannot be handled using libxml&#039;s error handling functions.
  </p>
  <p class="para">此方法<em class="emphasis">可以</em>被静态调用,但会抛出一个 <strong><code>E_STRICT</code></strong> 错误。</p>
 </div>

 <div class="refsect1 examples" id="refsect1-domdocument.loadxml-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-5290">
    <p><strong>Example #1 Creating a Document</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$doc&nbsp;</span><span style="color: #007700">=&nbsp;new&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;root&gt;&lt;node/&gt;&lt;/root&gt;'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
  <p class="para">
   <div class="example" id="example-5291">
    <p><strong>Example #2 Static invocation of <em>loadXML</em></strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;Issues&nbsp;an&nbsp;E_STRICT&nbsp;error<br /></span><span style="color: #0000BB">$doc&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">DOMDocument</span><span style="color: #007700">::</span><span style="color: #0000BB">loadXML</span><span style="color: #007700">(</span><span style="color: #DD0000">'&lt;root&gt;&lt;node/&gt;&lt;/root&gt;'</span><span style="color: #007700">);<br />echo&nbsp;</span><span style="color: #0000BB">$doc</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">saveXML</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>

 <div class="refsect1 seealso" id="refsect1-domdocument.loadxml-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="methodname"><a href="domdocument.load.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::load()</a> - Load XML from a file</span></li>
    <li class="member"><span class="methodname"><a href="domdocument.save.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::save()</a> - Dumps the internal XML tree back into a file</span></li>
    <li class="member"><span class="methodname"><a href="domdocument.savexml.html" class="methodname" rel="rdfs-seeAlso">DOMDocument::saveXML()</a> - Dumps the internal XML tree back into a string</span></li>
   </ul>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="domdocument.loadhtmlfile.html">DOMDocument::loadHTMLFile</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="domdocument.normalizedocument.html">DOMDocument::normalizeDocument</a></div>
 <div class="up"><a href="class.domdocument.html">DOMDocument</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
